﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;


namespace Lon.Server
{
    public class DataFrameFactry
    {
        public static DataFrame CreateStatusFrame(int srcId,int dstId,List<NetNode> nodes)
        {
            byte[] status = PackNodeStatusPackage(nodes);
            DataFrame df = new DataFrame(dstId, srcId, DataDir.StationData, false, false, false, 0x23, 0, status);
            return df;
        }
        private static byte[] PackNodeStatusPackage(List<NetNode> dbmList)
        {

            byte[] buf = new byte[4 + (dbmList.Count * 4)];
            BinaryWriter bw = new BinaryWriter(new MemoryStream(buf));
            bw.Write((int)(dbmList.Count * 4));
            foreach (NetNode node in dbmList)
            {
                int id = node.Id;
                bw.Write(id);
                bw.BaseStream.Seek(-1, SeekOrigin.Current);
                byte status = node.ConnectedState ? ((byte)1) : ((byte)0);
                bw.Write(status);
            }
            return buf;

        }
    }


}
